const MusicHttp = require("../../utils/MusicHttp")
Page({

  /**
   * 页面的初始数据
   */
  data: {
   detail:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: async function (options) {
    var {id} = options;
    console.log(id);
    var res =  await MusicHttp.getDetailMusicHttp(id)
        var detail = []
        var coverImgUrl = res.data.playlist.coverImgUrl;
        var description = res.data.playlist.description;
        var name = res.data.playlist.name;
        var playCount = res.data.playlist.playCount
        playCount = Math.floor(playCount/10000)+"万";
        var creator = res.data.playlist.creator;
        var uname;
       res.data.playlist.tracks.forEach(item=>{
         var {id,name,al,dt,ar} = item;
         dt = this.handleTime(dt)
         ar = ar[0].name;
         console.log(ar);
        //  console.log(dt);
         var picUrl = al.picUrl;
        uname = name;
          detail.push({
              uname,
              picUrl,
              id,
              dt,
              ar
          })
          // console.log(detail);
       })
       this.setData({
        coverImgUrl,
        description,
        name,
        playCount,
        creator,
        uname,
        detail
      })
    },
  handleTime(time){
    time = time/1000;
    var m = Math.floor(time/60);
    m = m<10?'0'+m:m;
    var s = Math.floor(time%60);
    s = s<10?'0'+s:s;
    return m+":"+s;
  },
  OnClick(e){
    var {aid} = e.currentTarget.dataset;
    console.log(aid);
    var uname = this.data.uname;
    wx.navigateTo({
      url: `../play/play?id=${aid}&name=${uname}`,
    })
  },
})